<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="customers.do"/>
<%@ page import="com.scalar.chiptrack.commons.SessionKeys,
                 com.scalar.chiptrack.sales.SalesPerson"%>
<%@ page import="com.scalar.chiptrack.commons.Constants"%>
<%@ page import="com.scalar.chiptrack.users.Functionality"%>
<%@ page import="com.scalar.chiptrack.users.User"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.util.Random"%>
<%@ page import="com.scalar.chiptrack.sales.ContactPerson"%>
<%@ page import="com.scalar.chiptrack.sales.dao.CustomerDAO"%>
<%@ page import="com.scalar.chiptrack.sales.forms.CustomerForm"%>
<%@ page import="com.scalar.chiptrack.sales.Customer"%>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>


<% String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>
<% User user1 = (User) session.getAttribute (SessionKeys.USER_KEY); %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<SCRIPT language="JavaScript">
<%
    HashMap contactPersonsList = (HashMap)request.getAttribute("customerContactPersonsMap");
    if(contactPersonsList != null)
    {
        int listSize = contactPersonsList.size();
        java.util.Iterator contactPersonsIterator = contactPersonsList.keySet().iterator();
        ContactPerson contactPersons[] = new ContactPerson[listSize];
        %>
            var contactPerson = new Array(<%=listSize%>);
            var phNo          = new Array(<%=listSize%>);
            var cellNo        = new Array(<%=listSize%>);
            var fax           = new Array(<%=listSize%>);
            var email         = new Array(<%=listSize%>);
            contactPerson[-3] = '';
            contactPerson[-2] = -1;
            contactPerson[-1] = '';
        <%
        for( int aa = 0; aa < listSize ; aa++)
        {
           Object key = contactPersonsIterator.next();
           if( contactPersonsList.get(key)!= null )
            {
                if(contactPersonsList.containsKey(key))
                {
                    contactPersons[aa] = (ContactPerson)contactPersonsList.get(key);
                    %>
                        contactPerson[<%=aa%>] = '<%=contactPersons[aa].getContactPerson().replaceAll("'","\\\\" + "'")%>';
                        phNo[<%=aa%>]          = '<%=contactPersons[aa].getPhoneNumber().replaceAll("'","\\\\" + "'")%>';
                        cellNo[<%=aa%>]        = '<%=contactPersons[aa].getCellNumber().replaceAll("'","\\\\" + "'")%>';
                        fax[<%=aa%>]           = '<%=contactPersons[aa].getFaxNumber().replaceAll("'","\\\\" + "'")%>';
                        email[<%=aa%>]         = '<%=contactPersons[aa].getEmail()%>';
                    <%
               }
           }
       } //for
   }
%>

<%
    HashMap billContactPersonsList = (HashMap)request.getAttribute("billingContactPersonsMap");
    if(billContactPersonsList != null)
    {
        int billListSize = billContactPersonsList.size();
        java.util.Iterator billContactPersonsIterator = billContactPersonsList.keySet().iterator();
        ContactPerson billContactPersons[] = new ContactPerson[billListSize];
        %>
            var billContactPerson = new Array(<%=billListSize%>);
            var billPhNo          = new Array(<%=billListSize%>);
            var billCellNo        = new Array(<%=billListSize%>);
            var billFax           = new Array(<%=billListSize%>);
            var billEmail         = new Array(<%=billListSize%>);
            billContactPerson[-3] = '';
            billContactPerson[-2] = -1;
            billContactPerson[-1] = '';
        <%
        for( int bb = 0; bb < billListSize ; bb++)
        {
           Object key = billContactPersonsIterator.next();
           if( billContactPersonsList.get(key)!= null )
            {
                if(billContactPersonsList.containsKey(key))
                {
                    billContactPersons[bb] = (ContactPerson)billContactPersonsList.get(key);
                    %>
                        billContactPerson[<%=bb%>] = '<%=billContactPersons[bb].getContactPerson().replaceAll("'","\\\\" + "'")%>';
                        billPhNo[<%=bb%>]          = '<%=billContactPersons[bb].getPhoneNumber().replaceAll("'","\\\\" + "'")%>';
                        billCellNo[<%=bb%>]        = '<%=billContactPersons[bb].getCellNumber().replaceAll("'","\\\\" + "'")%>';
                        billFax[<%=bb%>]           = '<%=billContactPersons[bb].getFaxNumber().replaceAll("'","\\\\" + "'")%>';
                        billEmail[<%=bb%>]         = '<%=billContactPersons[bb].getEmail()%>';
                    <%
               }
           }
       } //for
   }
%>

<%
    HashMap shipContactPersonsList = (HashMap)request.getAttribute("shippingContactPersonsMap");
    if(shipContactPersonsList != null)
    {
        int shipListSize = shipContactPersonsList.size();
        java.util.Iterator shipContactPersonsIterator = shipContactPersonsList.keySet().iterator();
        ContactPerson shipContactPersons[] = new ContactPerson[shipListSize];
        %>
            var shipContactPerson = new Array(<%=shipListSize%>);
            var shipPhNo          = new Array(<%=shipListSize%>);
            var shipCellNo        = new Array(<%=shipListSize%>);
            var shipFax           = new Array(<%=shipListSize%>);
            var shipEmail         = new Array(<%=shipListSize%>);
            shipContactPerson[-3] = '';
            shipContactPerson[-2] = -1;
            shipContactPerson[-1] = '';
        <%
        for( int dd = 0; dd < shipListSize ; dd++)
        {
           Object key = shipContactPersonsIterator.next();
           if( shipContactPersonsList.get(key)!= null )
            {
                if(shipContactPersonsList.containsKey(key))
                {
                    shipContactPersons[dd] = (ContactPerson)shipContactPersonsList.get(key);
                    %>
                        shipContactPerson[<%=dd%>] = '<%=shipContactPersons[dd].getContactPerson().replaceAll("'","\\\\" + "'")%>';
                        shipPhNo[<%=dd%>]          = '<%=shipContactPersons[dd].getPhoneNumber().replaceAll("'","\\\\" + "'")%>';
                        shipCellNo[<%=dd%>]        = '<%=shipContactPersons[dd].getCellNumber().replaceAll("'","\\\\" + "'")%>';
                        shipFax[<%=dd%>]           = '<%=shipContactPersons[dd].getFaxNumber().replaceAll("'","\\\\" + "'")%>';
                        shipEmail[<%=dd%>]         = '<%=shipContactPersons[dd].getEmail()%>';
                    <%
               }
           }
       } //for
   }
%>

function contactPersonss( contactPersonName, phNo, cellNo, fax, email )
{
	this.contactPersonName = contactPersonName;
	this.phNo = phNo;
	this.cellNo = cellNo;
	this.fax = fax;
	this.email = email;
}

<%
    HashMap allShippingContactPersonsList = (HashMap)request.getAttribute("allShippingContactPersonsMap");
    if(allShippingContactPersonsList != null)
    {
        int mapSize = allShippingContactPersonsList.size();
        java.util.Iterator allContactPersonsIterator = allShippingContactPersonsList.keySet().iterator();
		HashMap[] allContactPersons = new HashMap[mapSize];
		String[] addressId = new String[mapSize];
		%>
			var addId = new Array(<%=mapSize%>);
			var shippingAddressArray = new Array(<%=mapSize%>);
		<%
		for( int bb = 0; bb < mapSize ; bb++)
        {
             addressId[bb] = (String)allContactPersonsIterator.next();

		   %>
			    addId[<%=bb%>] =  '<%=addressId[bb]%>';
		   <%

           if( allShippingContactPersonsList.get(addressId[bb]) != null )
            {
                if(allShippingContactPersonsList.containsKey(addressId[bb]))
                {
					allContactPersons[bb] = (HashMap) allShippingContactPersonsList.get(addressId[bb]);
					if( allContactPersons[bb]  != null )
					{
						int[] contactPersonsSize = new int[mapSize];
						contactPersonsSize[bb] = allContactPersons[bb].size();
						Iterator[] contactPersonsIterator = new Iterator[mapSize];
						contactPersonsIterator[bb] = allContactPersons[bb].keySet().iterator();

						%>
						    var contactPersonArray = new Array(<%=contactPersonsSize[bb]%>);
						<%
						for( int cc = 0; cc < contactPersonsSize[bb] ; cc++)
						{
							 Object[] key = new Object[mapSize];
							 key[bb] = contactPersonsIterator[bb].next();
							 ContactPerson contactPersons[] = new ContactPerson[contactPersonsSize[bb]];
							if( allContactPersons[bb].get(key[bb]) != null )
							{
								if( allContactPersons[bb].containsKey(key[bb]) )
								{
									contactPersons[cc]	=  (ContactPerson)allContactPersons[bb].get(key[bb]);
									%>
									   contactPersonArray[<%=cc%>]= new contactPersonss('<%=contactPersons[cc].getContactPerson().replaceAll("'","\\\\" + "'")%>',
																						'<%=contactPersons[cc].getPhoneNumber().replaceAll("'","\\\\" + "'")%>',
																						'<%=contactPersons[cc].getCellNumber().replaceAll("'","\\\\" + "'")%>',
																						'<%=contactPersons[cc].getFaxNumber().replaceAll("'","\\\\" + "'")%>',
																						'<%=contactPersons[cc].getEmail()%>');
									<%
								}
							}

						}//for

					}//if( allContactPersons != null )

				}//if
			}//if
			 %>	 shippingAddressArray[<%=bb%>] = contactPersonArray ;  <%

        } //for
    }
    
    HashMap allBillingContactPersonsList = (HashMap)request.getAttribute("allBillingContactPersonsMap");
    if(allBillingContactPersonsList != null)
    {
        int mapSize = allBillingContactPersonsList.size();
        java.util.Iterator allContactPersonsIterator = allBillingContactPersonsList.keySet().iterator();
		HashMap[] allContactPersons = new HashMap[mapSize];
		String[] addressId = new String[mapSize];
		%>
			var billingAddId = new Array(<%=mapSize%>);
			var billingAddressArray = new Array(<%=mapSize%>);
		<%
		for( int bb = 0; bb < mapSize ; bb++)
        {
             addressId[bb] = (String)allContactPersonsIterator.next();

		   %>
			    billingAddId[<%=bb%>] =  '<%=addressId[bb]%>';
		   <%

           if( allBillingContactPersonsList.get(addressId[bb]) != null )
            {
                if(allBillingContactPersonsList.containsKey(addressId[bb]))
                {
					allContactPersons[bb] = (HashMap) allBillingContactPersonsList.get(addressId[bb]);
					if( allContactPersons[bb]  != null )
					{
						int[] contactPersonsSize = new int[mapSize];
						contactPersonsSize[bb] = allContactPersons[bb].size();
						Iterator[] contactPersonsIterator = new Iterator[mapSize];
						contactPersonsIterator[bb] = allContactPersons[bb].keySet().iterator();

						%>
						    var billingContactPersonArray = new Array(<%=contactPersonsSize[bb]%>);
						<%
						for( int cc = 0; cc < contactPersonsSize[bb] ; cc++)
						{
							 Object[] key = new Object[mapSize];
							 key[bb] = contactPersonsIterator[bb].next();
							 ContactPerson contactPersons[] = new ContactPerson[contactPersonsSize[bb]];
							if( allContactPersons[bb].get(key[bb]) != null )
							{
								if( allContactPersons[bb].containsKey(key[bb]) )
								{
									contactPersons[cc]	=  (ContactPerson)allContactPersons[bb].get(key[bb]);
									%>
									   billingContactPersonArray[<%=cc%>]= new contactPersonss('<%=contactPersons[cc].getContactPerson().replaceAll("'","\\\\" + "'")%>',
																						'<%=contactPersons[cc].getPhoneNumber().replaceAll("'","\\\\" + "'")%>',
																						'<%=contactPersons[cc].getCellNumber().replaceAll("'","\\\\" + "'")%>',
																						'<%=contactPersons[cc].getFaxNumber().replaceAll("'","\\\\" + "'")%>',
																						'<%=contactPersons[cc].getEmail()%>');
									<%
								}
							}

						}//for

					}//if( allContactPersons != null )

				}//if
			}//if
			 %>	 billingAddressArray[<%=bb%>] = billingContactPersonArray ;  <%

        } //for
    }

%>





<%
    ArrayList shipArr = (ArrayList)request.getAttribute("shippingMethods");
    int size1 =0;
    if(shipArr !=  null)
    {
        size1 = shipArr.size();
    }
%>
    var shppingLables = new Array(<%=size1%>);
    var shppingValues = new Array(<%=size1%>);
<%
   if( shipArr != null)
   {
    %>
        shppingLables[-2] = '';
        shppingLables[-1] = '';
   <%
    for(int s = 0 ; s < shipArr.size() ; s++)
    {
        %>
            shppingLables[<%=s%>] = '<%=((org.apache.struts.util.LabelValueBean)shipArr.get(s)).getLabel().replaceAll("'","\\\\" + "'")%>';
            shppingValues[<%=s%>] ='<%=((org.apache.struts.util.LabelValueBean)shipArr.get(s)).getValue().replaceAll("'","\\\\" + "'")%>';
        <%
    }%>
        shppingLables[<%=size1%>] = -2 ;
   <%
 } %>


 <%  ArrayList salesPersonsRegions = (ArrayList)request.getAttribute("salesPersonsRegionList");
    int size2 =0;
    if( salesPersonsRegions !=  null)
    {
        size2 = salesPersonsRegions.size();
    }
%>
    var salesPersons = new Array(<%=size2%>);
    var regionNames = new Array(<%=size2%>);
<%
   if( salesPersonsRegions != null)
   {
    Iterator itr  =  salesPersonsRegions.iterator() ;
    for(int s = 0 ; s < salesPersonsRegions.size() ; s++)
    {
        SalesPerson salesPerson = (SalesPerson)itr.next() ;
        %>
            salesPersons[<%=s%>] = '<%=salesPerson.getSalesPerson() %>';
            regionNames[<%=s%>] ='<%=salesPerson.getRegion() %>';
        <%
    }
 } %>

    function IsValidShippableQty(temp)
    {
        var errors = '';
        if(!isInteger(temp.value))
        {
            errors = 'Please enter a valid shippable quantity(only integers)';
        }
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
    }

    function IsValidCreditLimit(temp)
    {
        var errors = '';
        if(!isInteger(temp.value))
        {
            errors = 'Please enter a valid credit limit(only integers)';
        }
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
    }

    function applyBillingAddress()
    {
        if( document.customerForm.sameas.checked == true )   //Added by sarada on 28th Jan 2004
        {
            document.customerForm['customer.shippingAddress.address1'].value = document.customerForm['customer.billingAddress.address1'].value;
            document.customerForm['customer.shippingAddress.address2'].value = document.customerForm['customer.billingAddress.address2'].value;
            document.customerForm['customer.shippingAddress.address3'].value = document.customerForm['customer.billingAddress.address3'].value;
            document.customerForm['customer.shippingAddress.address4'].value = document.customerForm['customer.billingAddress.address4'].value;
            document.customerForm['customer.shippingAddress.city'].value =
			document.customerForm['customer.billingAddress.city'].value;
            document.customerForm['customer.shippingAddress.state'].value = document.customerForm['customer.billingAddress.state'].value;
            document.customerForm['customer.shippingAddress.zipCode'].value = document.customerForm['customer.billingAddress.zipCode'].value;
            document.customerForm['customer.shippingAddress.country'].value = document.customerForm['customer.billingAddress.country'].value;
         }

    }

    function load ()
	{
	    var locsize = document.getElementById('locSize').value;
	    var billingLocationsSize = document.getElementById('billingLocationsSize').value;
        //To persist the sameas value when form is reset
        var sameas = '<%=request.getParameter("sameas")%>'
        if( sameas == "yes" )
        {
            document.customerForm.sameas.checked = true;
        }

		for( aa = 0; aa < locsize; aa++)
		{
			if( document.customerForm['customer.shippingLocations['+aa+'].contactPerson'].value == '' ||    document.customerForm['customer.shippingLocations['+aa+'].contactPerson'].value == -1)
			{
				document.customerForm['customer.shippingLocations['+aa+'].contactPersonObject.phoneNumber'].disabled = true;
				document.customerForm['customer.shippingLocations['+aa+'].contactPersonObject.cellNumber'].disabled = true;

				document.customerForm['customer.shippingLocations['+aa+'].contactPersonObject.faxNumber'].disabled = true;
				document.customerForm['customer.shippingLocations['+aa+'].contactPersonObject.email'].disabled = true;
			}
		}
        for( aa = 0; aa < billingLocationsSize; aa++)
		{
			if( document.customerForm['customer.billingLocations['+aa+'].contactPerson'].value == '' ||    document.customerForm['customer.billingLocations['+aa+'].contactPerson'].value == -1)
			{
				document.customerForm['customer.billingLocations['+aa+'].contactPersonObject.phoneNumber'].disabled = true;
				document.customerForm['customer.billingLocations['+aa+'].contactPersonObject.cellNumber'].disabled = true;

				document.customerForm['customer.billingLocations['+aa+'].contactPersonObject.faxNumber'].disabled = true;
				document.customerForm['customer.billingLocations['+aa+'].contactPersonObject.email'].disabled = true;
			}
		}

        if( document.customerForm['customer.contactPerson'].value == '' || document.customerForm['customer.contactPerson'].value == -1 )
		{
			document.customerForm['customer.contactPersonObject.phoneNumber'].disabled = true;
			document.customerForm['customer.contactPersonObject.cellNumber'].disabled = true;
			document.customerForm['customer.contactPersonObject.faxNumber'].disabled = true;
			document.customerForm['customer.contactPersonObject.email'].disabled = true;
		}

		if( document.customerForm['customer.billingAddress.contactPerson'].value == '' || document.customerForm['customer.billingAddress.contactPerson'].value == -1 )
		{
			document.customerForm['customer.billingContactPersonObject.phoneNumber'].disabled = true;
			document.customerForm['customer.billingContactPersonObject.cellNumber'].disabled = true;
			document.customerForm['customer.billingContactPersonObject.faxNumber'].disabled = true;
			document.customerForm['customer.billingContactPersonObject.email'].disabled = true;
		}

		if( document.customerForm['customer.shippingAddress.contactPerson'].value == '' || document.customerForm['customer.shippingAddress.contactPerson'].value == -1 )
		{
			document.customerForm['customer.shippingContactPersonObject.phoneNumber'].disabled = true;
			document.customerForm['customer.shippingContactPersonObject.cellNumber'].disabled = true;
			document.customerForm['customer.shippingContactPersonObject.faxNumber'].disabled = true;
			document.customerForm['customer.shippingContactPersonObject.email'].disabled = true;
		}


        var pa1  = document.getElementById("newShippingMethod1");
        var pa11 = document.getElementById("newShippingAccount1");
         <%
             String addShipMethod = request.getParameter("shipAccount1");

             if(addShipMethod==null || (!addShipMethod.equals("-2")))
             {
                 %>
                    document.customerForm['customer.newShippingMethod1'].style.visibility = "hidden";
                    pa1.innerHTML = "&nbsp;";
                    document.customerForm['customer.newShippingAccount1'].style.visibility = "hidden";
                    pa11.innerHTML = "&nbsp;";
                 <%
             }
             if((addShipMethod!=null) && (!addShipMethod.trim().equals("")))
             {
                 %>
                 document.customerForm['customer.shippingMethod1'].value = '<%=addShipMethod%>';
                 document.customerForm.shipAccount1.value = '<%=addShipMethod%>';
                 <%
             }
         %>
         if ( document.customerForm['customer.shippingMethod1'].value == "" )
         {
            document.customerForm['customer.shippingMethod1'].value = "-1";
         }

         document.customerForm['customer.newRegion'].style.visibility="hidden";
         document.customerForm['customer.newRepOffice'].style.visibility="hidden";
         document.customerForm['customer.newSalesPerson'].style.visibility="hidden";
         document.customerForm['customer.newSalesRep'].style.visibility="hidden";
        var pa = document.getElementById("shippingInstructions");
        if ( document.customerForm['customer.shippingInstructions'].value == -2 )
        {
            pa.innerHTML = "New <bean:message key="label.sales.shippingInstructions" />"
            document.customerForm['customer.shippingInstructions'].readOnly = false;
        }
        else
        {
            pa.innerHTML = "<bean:message key="label.sales.shippingInstructions" />"
            document.customerForm['customer.shippingInstructions'].readOnly = true;
        }
        var shippingLabel = document.getElementById("newShippingTerms");
        if( document.customerForm['customer.shippingTerms'].value == -2 )
		{
			document.customerForm['customer.newShippingTerms'].style.visibility = "visible";
			shippingLabel.innerHTML = "New Pay Terms : ";
		}
		else
		{
			document.customerForm['customer.newShippingTerms'].style.visibility = "hidden";
			shippingLabel.innerHTML = "";
		}
        
        showHideIsDefaultConsignment();
        showHideDistributerOptions();
    }

    function onCheck() {

        var pa1  = document.getElementById("newShippingMethod1");
        var pa11 = document.getElementById("newShippingAccount1");

         document.customerForm['customer.newRegion'].style.visibility="hidden";
         document.customerForm['customer.newRepOffice'].style.visibility="hidden";
         document.customerForm['customer.newSalesPerson'].style.visibility="hidden";
         document.customerForm['customer.newSalesRep'].style.visibility="hidden";
    }

    function getNewElements(addElement)
    {
        if(addElement == 'Region')
        {
            var actionValue = document.customerForm.action.value;
            var customerId = document.customerForm['customer.customerId'].value ;

            if (document.customerForm['customer.region'].value == -1)
            {
                newWindow = window.open ('<%=chipTracContext%>/addNewRegion.do?customerId='+customerId,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=500,height=500,resizable=no');
                if(!newWindow.opener) {newWindow.opener = window}
                newWindow.focus();
                document.customerForm['customer.region'].value = " ";
            }
        }
        if(addElement == 'Rep Office')
        {
            var actionValue = document.customerForm.action.value;
            var customerId = document.customerForm['customer.customerId'].value ;
            if (document.customerForm['customer.repOffice'].value == -1)
            {
                newWindow = window.open ('<%=chipTracContext%>/addNewRepOffice.do?customerId='+customerId,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=500,height=500,resizable=no');
                if(!newWindow.opener) {newWindow.opener = window}
                newWindow.focus();
                document.customerForm['customer.repOffice'].value = " ";
            }

        }
        if(addElement == 'Sales Person')
        {
            var actionValue = document.customerForm.action.value;
            var customerId = document.customerForm['customer.customerId'].value ;
            var LeftPos=(screen.width)?(screen.width-900)/2:100;
            var TopPos=(screen.height)?(screen.height-450)/2:100;


            if (document.customerForm['customer.salesPerson'].value == -1)
            {
                newWindow = window.open ('<%=chipTracContext%>/addNewSalesPerson.do?customerId='+customerId,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=650,height=550,Left= '+LeftPos+',top='+TopPos+',resizable=no');
                if(!newWindow.opener) {newWindow.opener = window}
                newWindow.focus();
                document.customerForm['customer.salesPerson'].value = " ";
            }

        }
        if(addElement == 'Sales Rep')
        {
            var actionValue = document.customerForm.action.value;
            var customerId = document.customerForm['customer.customerId'].value ;
            if (document.customerForm['customer.salesRep'].value == -1)
            {
                newWindow = window.open ('<%=chipTracContext%>/addNewSalesRep.do?customerId='+customerId,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=500,height=500,resizable=no');
                if(!newWindow.opener) {newWindow.opener = window}
                newWindow.focus();
                document.customerForm['customer.salesRep'].value = " ";
            }

        }
    }

    function selectContactPerson (element,idValue, indexValue)
    {
	    var yy = document.customerForm['customer.contactPerson'].selectedIndex;

        if( element =='CustomerContactPerson' )
	    {
			for( ss = 0; ss < contactPerson.length; ss++ )
			{

				if( document.customerForm['customer.contactPerson'].value == contactPerson[ss] )
				{
					 document.customerForm['customer.contactPerson'].value = contactPerson[ss];
					 document.customerForm['customer.contactPersonObject.phoneNumber'].value = phNo[ss];
					 document.customerForm['customer.contactPersonObject.cellNumber'].value = cellNo[ss];
					 document.customerForm['customer.contactPersonObject.faxNumber'].value = fax[ss];
					 document.customerForm['customer.contactPersonObject.email'].value = email[ss];

					 document.customerForm['customer.contactPersonObject.phoneNumber'].disabled = false;
					 document.customerForm['customer.contactPersonObject.cellNumber'].disabled = false;
					 document.customerForm['customer.contactPersonObject.faxNumber'].disabled = false;
					 document.customerForm['customer.contactPersonObject.email'].disabled = false;
				}
				else  if( document.customerForm['customer.contactPerson'].value == '' )
				{
					 document.customerForm['customer.contactPerson'].value = '';
					 document.customerForm['customer.contactPersonObject.phoneNumber'].value = '';
					 document.customerForm['customer.contactPersonObject.cellNumber'].value = '';
					 document.customerForm['customer.contactPersonObject.faxNumber'].value = '';
					 document.customerForm['customer.contactPersonObject.email'].value = '';

					 document.customerForm['customer.contactPersonObject.phoneNumber'].disabled = true;
					 document.customerForm['customer.contactPersonObject.cellNumber'].disabled = true;
					 document.customerForm['customer.contactPersonObject.faxNumber'].disabled = true;
					 document.customerForm['customer.contactPersonObject.email'].disabled = true;
				}
			}
				if(document.customerForm['customer.contactPerson'].value == -1)
				{
					var customerId = document.customerForm['customer.customerId'].value ;
                    newWindow = window.open ('<%=chipTracContext%>/addNewContactPerson.do?value=Customer&customerId='+customerId,'billOptionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=650,height=500,resizable=no');
					if(!newWindow.opener) {newWindow.opener = window}
					newWindow.focus();

					 document.customerForm['customer.contactPersonObject.phoneNumber'].value = '';
					 document.customerForm['customer.contactPersonObject.cellNumber'].value = '';
					 document.customerForm['customer.contactPersonObject.faxNumber'].value = '';
					 document.customerForm['customer.contactPersonObject.email'].value = '';

				 }

		}
		 var ww = document.customerForm['customer.billingAddress.contactPerson'].selectedIndex;
		if( element =='BillingContactPerson' )
		{

			 for( pp = 0; pp < billContactPerson.length; pp++ )
			 {
				if( document.customerForm['customer.billingAddress.contactPerson'].value == billContactPerson[pp] )
				{
					 document.customerForm['customer.billingAddress.contactPerson'].value = billContactPerson[pp];

					 document.customerForm['customer.billingContactPersonObject.phoneNumber'].value = billPhNo[pp];
					 document.customerForm['customer.billingContactPersonObject.cellNumber'].value = billCellNo[pp];
					 document.customerForm['customer.billingContactPersonObject.faxNumber'].value = billFax[pp];
					 document.customerForm['customer.billingContactPersonObject.email'].value = billEmail[pp];

					 document.customerForm['customer.billingContactPersonObject.phoneNumber'].disabled = false;
					 document.customerForm['customer.billingContactPersonObject.cellNumber'].disabled = false;
					 document.customerForm['customer.billingContactPersonObject.faxNumber'].disabled = false;
					 document.customerForm['customer.billingContactPersonObject.email'].disabled = false;
				}
				else
				if( document.customerForm['customer.billingAddress.contactPerson'].value == '' )
				{
					 document.customerForm['customer.billingAddress.contactPerson'].value = '';
					 document.customerForm['customer.billingContactPersonObject.phoneNumber'].value = '';
					 document.customerForm['customer.billingContactPersonObject.cellNumber'].value = '';
					 document.customerForm['customer.billingContactPersonObject.faxNumber'].value = '';
					 document.customerForm['customer.billingContactPersonObject.email'].value = '';

					 document.customerForm['customer.billingContactPersonObject.phoneNumber'].disabled = true;
					 document.customerForm['customer.billingContactPersonObject.cellNumber'].disabled = true;
					 document.customerForm['customer.billingContactPersonObject.faxNumber'].disabled = true;
					 document.customerForm['customer.billingContactPersonObject.email'].disabled = true;

				}
			 }

			if( document.customerForm['customer.billingAddress.contactPerson'].value == -1)
			{
				var billingAddressId = document.customerForm['customer.defaultBillingAddressId'].value ;
				var contactPerson1 = document.customerForm['customer.billingAddress.contactPerson'].value;

				if (billingAddressId == -1)
                {
					billingAddressId = document.customerForm['customer.billAddressId'].value;
				}
                newWindow = window.open ('<%=chipTracContext%>/addNewContactPerson.do?value=Address&customerId='+billingAddressId,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=650,height=500,resizable=no');
				if(!newWindow.opener) {newWindow.opener = window}
				newWindow.focus();

				 document.customerForm['customer.billingContactPersonObject.phoneNumber'].value = '';
				 document.customerForm['customer.billingContactPersonObject.cellNumber'].value = '';
				 document.customerForm['customer.billingContactPersonObject.faxNumber'].value = '';
				 document.customerForm['customer.billingContactPersonObject.email'].value = '';
			}
		}

		if( element =='ShippingContactPerson' )
		{

			 for( ff = 0; ff < shipContactPerson.length; ff++ )
			 {
				if( document.customerForm['customer.shippingAddress.contactPerson'].value == shipContactPerson[ff] )
				{
					 document.customerForm['customer.shippingAddress.contactPerson'].value = shipContactPerson[ff];

					 document.customerForm['customer.shippingContactPersonObject.phoneNumber'].value = shipPhNo[ff];
					 document.customerForm['customer.shippingContactPersonObject.cellNumber'].value = shipCellNo[ff];
					 document.customerForm['customer.shippingContactPersonObject.faxNumber'].value = shipFax[ff];
					 document.customerForm['customer.shippingContactPersonObject.email'].value = shipEmail[ff];

					 document.customerForm['customer.shippingContactPersonObject.phoneNumber'].disabled = false;
					 document.customerForm['customer.shippingContactPersonObject.cellNumber'].disabled = false;
					 document.customerForm['customer.shippingContactPersonObject.faxNumber'].disabled = false;
					 document.customerForm['customer.shippingContactPersonObject.email'].disabled = false;
				}
				else
				if( document.customerForm['customer.shippingAddress.contactPerson'].value == '' )
				{
					 document.customerForm['customer.shippingAddress.contactPerson'].value = '';
					 document.customerForm['customer.shippingContactPersonObject.phoneNumber'].value = '';
					 document.customerForm['customer.shippingContactPersonObject.cellNumber'].value = '';
					 document.customerForm['customer.shippingContactPersonObject.faxNumber'].value = '';
					 document.customerForm['customer.shippingContactPersonObject.email'].value = '';

					 document.customerForm['customer.shippingContactPersonObject.phoneNumber'].disabled = true;
					 document.customerForm['customer.shippingContactPersonObject.cellNumber'].disabled = true;
					 document.customerForm['customer.shippingContactPersonObject.faxNumber'].disabled = true;
					 document.customerForm['customer.shippingContactPersonObject.email'].disabled = true;

				}
			 }

			if( document.customerForm['customer.shippingAddress.contactPerson'].value == -1)
			{
				var shippingAddressId = document.customerForm['customer.defaultShippingAddressId'].value ;
				var contactPerson1 = document.customerForm['customer.shippingAddress.contactPerson'].value;
				if (shippingAddressId == -1)
                {
					shippingAddressId = document.customerForm['customer.shipAddressId'].value;
				}
                newWindow = window.open ('<%=chipTracContext%>/addNewContactPerson.do?value=Address&customerId='+shippingAddressId,'shipOptionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=650,height=500,resizable=no');
				if(!newWindow.opener) {newWindow.opener = window}
				newWindow.focus();

				 document.customerForm['customer.shippingContactPersonObject.phoneNumber'].value = '';
				 document.customerForm['customer.shippingContactPersonObject.cellNumber'].value = '';
				 document.customerForm['customer.shippingContactPersonObject.faxNumber'].value = '';
				 document.customerForm['customer.shippingContactPersonObject.email'].value = '';
			}
		}

		if( element =='ShippingLocationContactPerson' )
	    {
			var selectedContactPerson = document.customerForm['customer.shippingLocations['+indexValue+'].contactPerson'].value;
			var customerId = document.customerForm['customer.customerId'].value ;
			var id = document.customerForm['customer.shippingLocations['+indexValue+'].locAddressId'].value;

			var someValue = new Array();
			for( ss = 0;ss < shippingAddressArray.length; ss++)
			{
				if( customerId == -1)
				{
					if( addId[ss] == id )
					{
						someValue = shippingAddressArray[ss];
						var  cpValue = new Array();
						for( aa =0 ; aa < someValue.length ; aa++)
						{
							cpValue[aa] = someValue[aa];
							if( cpValue[aa].contactPersonName == selectedContactPerson )
							{
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPerson'].value = cpValue[aa].contactPersonName;
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = cpValue[aa].phNo;
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = cpValue[aa].cellNo;

								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = cpValue[aa].fax;
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].value = cpValue[aa].email;

								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = false;
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = false;

								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = false;
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].disabled = false;
							}
							else
							if(selectedContactPerson == '')
							{
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPerson'].value = '';
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = '';
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = '';

								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = '';
								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].value = '';

								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = true;

								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = true;

								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = true;

								document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].disabled = true;


							}
						}//for
					}//if
				 }//if( customerId == -1)
				 else
				{
                    if( addId[ss] < 0 )
					{
						if( addId[ss] == id )
						{
							someValue = shippingAddressArray[ss];
							var  cpValue = new Array();
							for( aa =0 ; aa < someValue.length ; aa++)
							{
								cpValue[aa] = someValue[aa];
								if( cpValue[aa].contactPersonName == selectedContactPerson )
								{
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPerson'].value = cpValue[aa].contactPersonName;
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = cpValue[aa].phNo;
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = cpValue[aa].cellNo;

									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = cpValue[aa].fax;
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].value = cpValue[aa].email;


									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = false;
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = false;

									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = false;
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].disabled = false;
								}
								else
								if(selectedContactPerson == '')
								{
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPerson'].value = '';
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = '';
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = '';

									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = '';
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].value = '';

									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = true;
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = true;

									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = true;
									document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].disabled = true;

								}
							}//for
						}//if
					}//if
							else  if( addId[ss] > 0 )
							{
								if( addId[ss] == idValue )
								{
									someValue = shippingAddressArray[ss];
									var  cpValue = new Array();
									for( aa =0 ; aa < someValue.length ; aa++)
									{
										cpValue[aa] = someValue[aa];
										if( cpValue[aa].contactPersonName == selectedContactPerson )
										{
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPerson'].value = cpValue[aa].contactPersonName;
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = cpValue[aa].phNo;
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = cpValue[aa].cellNo;

											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = cpValue[aa].fax;
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].value = cpValue[aa].email;

											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = false;
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = false;

											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = false;
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].disabled = false;
										}
										else
										if(selectedContactPerson == '')
										{
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPerson'].value = '';
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = '';
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = '';

											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = '';
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].value = '';

											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = true;
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = true;

											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = true;
											document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].disabled = true;

										}

									}//for
								}//if
					    }//elseif

				  } //else

			}//for
				if( selectedContactPerson == -1)
				{
						if(idValue == -1 )
						{
							var id = document.customerForm['customer.shippingLocations['+indexValue+'].locAddressId'].value ;
							idValue = id ;

						}
						newWindow = window.open ('<%=chipTracContext%>/addNewContactPerson.do?value=Address&customerId='+idValue,'shipLocOptionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=650,height=500,resizable=no');
						if(!newWindow.opener) {newWindow.opener = window}
						newWindow.focus();

						document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = '';
						document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = '';

						document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = '';
						document.customerForm['customer.shippingLocations['+indexValue+'].contactPersonObject.email'].value = '';

				}

			}//if( element =='ShippingLocationContactPerson' )
        if( element =='BillingLocationContactPerson' )
	    {
			var selectedContactPerson = document.customerForm['customer.billingLocations['+indexValue+'].contactPerson'].value;
			var customerId = document.customerForm['customer.customerId'].value ;
			var id = document.customerForm['customer.billingLocations['+indexValue+'].locAddressId'].value;

			var someValue = new Array();
			for( ss = 0;ss < billingAddressArray.length; ss++)
			{
				if( customerId == -1)
				{
					if( billingAddId[ss] == id )
					{
						someValue = billingAddressArray[ss];
						var  cpValue = new Array();
						for( aa =0 ; aa < someValue.length ; aa++)
						{
							cpValue[aa] = someValue[aa];
							if( cpValue[aa].contactPersonName == selectedContactPerson )
							{
								document.customerForm['customer.billingLocations['+indexValue+'].contactPerson'].value = cpValue[aa].contactPersonName;
								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = cpValue[aa].phNo;
								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = cpValue[aa].cellNo;

								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = cpValue[aa].fax;
								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].value = cpValue[aa].email;

								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = false;
								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = false;

								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = false;
								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].disabled = false;
							}
							else
							if(selectedContactPerson == '')
							{
								document.customerForm['customer.billingLocations['+indexValue+'].contactPerson'].value = '';
								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = '';
								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = '';

								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = '';
								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].value = '';

								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = true;

								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = true;

								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = true;

								document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].disabled = true;


							}
						}//for
					}//if
				 }//if( customerId == -1)
				 else
				{
                    if( billingAddId[ss] < 0 )
					{
						if( billingAddId[ss] == id )
						{
							someValue = billingAddressArray[ss];
							var  cpValue = new Array();
							for( aa =0 ; aa < someValue.length ; aa++)
							{
								cpValue[aa] = someValue[aa];
								if( cpValue[aa].contactPersonName == selectedContactPerson )
								{
									document.customerForm['customer.billingLocations['+indexValue+'].contactPerson'].value = cpValue[aa].contactPersonName;
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = cpValue[aa].phNo;
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = cpValue[aa].cellNo;

									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = cpValue[aa].fax;
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].value = cpValue[aa].email;


									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = false;
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = false;

									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = false;
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].disabled = false;
								}
								else
								if(selectedContactPerson == '')
								{
									document.customerForm['customer.billingLocations['+indexValue+'].contactPerson'].value = '';
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = '';
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = '';

									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = '';
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].value = '';

									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = true;
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = true;

									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = true;
									document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].disabled = true;

								}
							}//for
						}//if
					}//if
							else  if( billingAddId[ss] > 0 )
							{
								if( billingAddId[ss] == idValue )
								{
									someValue = billingAddressArray[ss];
									var  cpValue = new Array();
									for( aa =0 ; aa < someValue.length ; aa++)
									{
										cpValue[aa] = someValue[aa];
										if( cpValue[aa].contactPersonName == selectedContactPerson )
										{
											document.customerForm['customer.billingLocations['+indexValue+'].contactPerson'].value = cpValue[aa].contactPersonName;
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = cpValue[aa].phNo;
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = cpValue[aa].cellNo;

											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = cpValue[aa].fax;
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].value = cpValue[aa].email;

											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = false;
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = false;

											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = false;
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].disabled = false;
										}
										else
										if(selectedContactPerson == '')
										{
											document.customerForm['customer.billingLocations['+indexValue+'].contactPerson'].value = '';
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = '';
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = '';

											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = '';
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].value = '';

											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].disabled = true;
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].disabled = true;

											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].disabled = true;
											document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].disabled = true;

										}

									}//for
								}//if
					    }//elseif

				  } //else

			}//for
				if( selectedContactPerson == -1)
				{
						if(idValue == -1 )
						{
							var id = document.customerForm['customer.billingLocations['+indexValue+'].locAddressId'].value ;
							idValue = id ;

						}
						newWindow = window.open ('<%=chipTracContext%>/addNewContactPerson.do?value=Address&customerId='+idValue,'shipLocOptionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=650,height=500,resizable=no');
						if(!newWindow.opener) {newWindow.opener = window}
						newWindow.focus();

						document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.phoneNumber'].value = '';
						document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.cellNumber'].value = '';

						document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.faxNumber'].value = '';
						document.customerForm['customer.billingLocations['+indexValue+'].contactPersonObject.email'].value = '';

				}

			}
   }

    function selectPartNumbers()
    {
        var custId =  document.customerForm['customer.customerId'].value;
        var LeftPos=(screen.width)?(screen.width-850)/2:100;
        var TopPos=(screen.height)?(screen.height-600)/2:100;
        newWindow = window.open ('<%=chipTracContext%>/customerPartNumbers.do?customerId='+custId,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=850,height=600,resizable=no Left= '+LeftPos+',top='+TopPos);
        if(!newWindow.opener) {newWindow.opener = window}
        newWindow.focus();
    }

   function addShippingMethod(methodname)
   {
        var pa1  = document.getElementById("newShippingMethod1");
        var pa11 = document.getElementById("newShippingAccount1");
        document.customerForm.shipAccount1.value = document.customerForm['customer.shippingMethod1'].value;

    if(methodname.name == document.customerForm['customer.shippingMethod1'].name )
       {
          var ss = document.customerForm['customer.shippingMethod1'].selectedIndex;
          document.customerForm.shipMethod1.value = document.customerForm['customer.shippingMethod1'].value;//shppingLables[ss-2];

          if (methodname.value == -2)
          {
              if ( document.customerForm['customer.customerId'].value <= 0 )
              {
                document.customerForm['customer.newShippingMethod1'].style.visibility = "visible";
                pa1.innerHTML = "<bean:message key="label.sales.salesOrder.NewShippingMethod"/>:&nbsp;<font color=red>*</font>";

                document.customerForm['customer.newShippingAccount1'].style.visibility = "visible";
                pa11.innerHTML = "<bean:message key="label.sales.salesOrder.NewShippingAccount"/>:&nbsp;<font color=red>*</font>";
              }
              else
              {
                var form = document.customerForm;
                form.shipAccount1.value = -1;
                form.shipMethod1.value = -1;
                form['customer.shippingMethod1'].value = -1;
                document.customerForm['customer.shippingAccount1'].value = '';
                var LeftPos=(screen.width)?(screen.width-500)/2:100;
                var TopPos=(screen.height)?(screen.height-450)/2:100;
                newWindow = window.open ('<%=chipTracContext%>/shippingMethodPopupAction.do?action=load&fromScreen=customer&customerId='+form['customer.customerId'].value+"&endCustomerId=0","editShippingMethod",'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=540,height=500,resizable=yes,Left= '+LeftPos+',top='+TopPos);
                newWindow.focus();
              }
          }
          else
          {
                document.customerForm['customer.newShippingMethod1'].value='';
                document.customerForm['customer.newShippingAccount1'].value='';

                document.customerForm['customer.newShippingMethod1'].style.visibility = "hidden";
                pa1.innerHTML = "&nbsp;";

                document.customerForm['customer.newShippingAccount1'].style.visibility = "hidden";
                pa11.innerHTML = "&nbsp;";

                assignShippingAccount(methodname);
             }
       }

   }


 function assignShippingAccount(elementName)
    {

        var len = elementName.length;
        if(elementName.name == document.customerForm['customer.shippingMethod1'].name )
        {
           if(document.customerForm['customer.shippingMethod1'].value != -1)
           {
               document.customerForm['customer.shippingAccount1'].value = elementName.value;
           }
           else
           if(document.customerForm['customer.shippingMethod1'].value == -1)
           {
               document.customerForm['customer.shippingAccount1'].value = '';
           }

        }
    }

    function submitpage(theForm)
    {
        var errors ='';
        var i=0;
        var a = document.getElementById('locSize').value;
        var cust = document.customerForm['customer.customerName'];
        var custNo = document.customerForm['customer.customerNumber'];
        var custId = document.customerForm['customer.customerId'];


		var email = document.customerForm['customer.billingAddress.email'];
        var customeremail = document.customerForm['customer.contactPersonObject.email'];
        var billingemail = document.customerForm['customer.billingContactPersonObject.email'];
        var shippingemail = document.customerForm['customer.shippingContactPersonObject.email'];
        var shippingInstructions = document.customerForm['customer.shippingInstructions'];
        var shippingTerms = document.customerForm["customer.shippingTerms"];
        var customerType = document.customerForm['customer.selectedCustomerTypes'];
        var jitWindow    = document.customerForm['customer.jitWindow'];
        var typeSelected = false;

        if( !customerType.length )
        {
            if ( customerType.checked == true )
            {
                typeSelected = true;
            }
        }
        else
        {
            for ( var i = 0; i < customerType.length ; i++ )
            {
                if ( customerType[i].checked == true )
                {
                    typeSelected = true;
                }
            }
        }

        if( typeSelected == false )
        {
            errors = 'Please Select Atleast one Type for Customer';
        }

        if( (trim(cust.value) == '') || (trim(cust.value).length == 0) )
        {
            errors = 'Please enter Customer Name';
        }
        if( ( trim(custNo.value) == '' || trim(custNo.value).length == 0 ) && custId.value < 0 )
        {
            errors = 'Please enter Customer Number';
        }

        if( email.value != '' )
	    {
            if( !isValidEMailId (email) )
            {
               errors = errors + '<br>'+'Please enter a valid  customer email address';
               email.select();
               email.focus();
            }
         }
        var shipTerms = document.customerForm['customer.shippingTerms'].value;
		var newshipTerms = document.customerForm['customer.newShippingTerms'].value;
		if( shipTerms == -2 )
		{
			if( newshipTerms == '' || newshipTerms.trim().length == 0 )
			{
				errors = '<br>'+' Enter New Pay Terms ';
			}
            else if( newshipTerms.indexOf('\'') >=0 || newshipTerms.indexOf('"') >= 0 )
            {
                errors = '<br>'+' Enter Valid Pay Terms ';
                document.customerForm['customer.newShippingTerms'].select();
                document.customerForm['customer.newShippingTerms'].focus();
            }
		}

        if( customeremail.value != '' )
	    {
            if( !isValidEMailId (customeremail) )
            {
               errors = errors + '<br>'+'Please enter a  valid email address';
               customeremail.select();
               customeremail.focus();
           }
        }

         if( billingemail.value != '' )
	      {
                if( !isValidEMailId (billingemail) )
                {
                   errors = errors + '<br>'+'Please enter a valid email address';
                   billingemail.select();
                   billingemail.focus();
                }
          }
        if( shippingemail.value != '' )
	    {
            if( !isValidEMailId (shippingemail) )
            {
               errors = '<br>'+'Please enter a valid email address';
               shippingemail.select();
               shippingemail.focus();
            }
        }

        if( (text_area(shippingInstructions.value)) == true)
        {
            errors = errors + '<br>' + "<li>  ShippingInstructions should not exceed 300 characters";
        }
        if( jitWindow.value != '')
        {
            if( !isInteger (jitWindow.value) )
            {
                errors = '<br>'+'Please enter a valid integer';
                jitWindow.select();
                jitWindow.focus();
            }
        }
        while(i < a)
        {
          var email = document.customerForm['customer.shippingLocations['+i+'].contactPersonObject.email'];
            if( email.value != '' )
            {
                if( !isValidEMailId (email) )
                {
                   errors = errors + '<br>'+'Please enter a valid email address';
                   email.select();
                   email.focus();
                }
           }
          i++;
        }

        var method1     = document.customerForm['customer.shippingMethod1'].value;
        var account1    = document.customerForm['customer.shippingAccount1'].value;
        var newmethod1  = document.customerForm['customer.newShippingMethod1'].value;
        var newaccount1 = document.customerForm['customer.newShippingAccount1'].value;

        var temp = document.customerForm['customer.shippingMethod1'].selectedIndex;
        document.customerForm.shipMethod1.value = shppingLables[temp-2];



      if( method1 == -2)
      {

         if( trim(newmethod1) == '')
         {
            errors = '<br>'+'Enter <bean:message key="label.sales.salesOrder.NewShippingMethod"/> ';
            document.customerForm['customer.newShippingMethod1'].focus();
         }
         if( trim(newaccount1) == '')
         {
            errors = errors + '<br>'+'Enter <bean:message key="label.sales.salesOrder.NewShippingAccount"/> ';
            document.customerForm['customer.newShippingAccount1'].focus();
         }
         if(newmethod1.indexOf('\'')>=0 || newmethod1.indexOf('"')>=0 || newmethod1.indexOf('#')>=0)
         {
            errors = errors + '<br>'+'Enter Valid <bean:message key="label.sales.salesOrder.NewShippingMethod" /> ( \' " # are not allowed )';
            document.customerForm['customer.newShippingMethod1'].select();
            document.customerForm['customer.newShippingMethod1'].focus();
         }
         if(newaccount1.indexOf('\'')>=0 || newaccount1.indexOf('"')>=0 || newaccount1.indexOf('#')>=0)
         {
            errors = errors + '<br>'+'Enter Valid <bean:message key="label.sales.salesOrder.NewShippingAccount" /> ( \' " # are not allowed )';
            document.customerForm['customer.newShippingAccount1'].select();
            document.customerForm['customer.newShippingAccount1'].focus();
         }
        var tempShippingMethod =  newmethod1.trim()+'   #   '+newaccount1.trim();
        for(var i = 0; i < shppingLables.length - 1; i++)
        {
            if(  shppingLables[i].toUpperCase() == tempShippingMethod.toUpperCase() )
            {
                errors = newmethod1 + ' <bean:message key="label.sales.salesOrder.ShippingMethod" /> already Exists, Please enter another <bean:message key="label.sales.salesOrder.ShippingMethod" />';
                document.customerForm['customer.newShippingMethod1'].select();
                document.customerForm['customer.newShippingMethod1'].focus();
            }
        }
     }


     if(errors != '')
        {
            var pa=document.getElementById("errors");
            pa.innerHTML = errors;
            return;
        }

        if(compareRegion() == false) return;
        if(compareRepOffice() == false) return;
        i = 0;

        var billingLocationsSize = document.getElementById('billingLocationsSize').value;
        while(i < billingLocationsSize)
        {
            if(document.customerForm['customer.billingLocations['+i+'].defaultAddress'].checked == true)
            {
                if(trim(document.customerForm['customer.billingLocations['+i+'].address1'].value).length == 0)
                {
                    var pa=document.getElementById("errors");
                    pa.innerHTML = 'Address 1 cannot be blank if a Billing Address is selected as Default Billing Address';
                    document.customerForm['customer.billingLocations['+i+'].address1'].focus();
                    return;
                }
                if( document.customerForm['customer.billingLocations['+i+'].defaultAddress'].checked == true
                && document.customerForm['customer.billingLocations['+i+'].remove'].checked == true )
                {

                     var pa1=document.getElementById("errors");
                     pa1.innerHTML = '<br>'+'Both  Remove and DefaultBillingAddress should not be selected ';
                     return;
                }

            }
            i++;
        }

        i=0;
        while(i < a)
        {
            if(document.customerForm['customer.shippingLocations['+i+'].defaultAddress'].checked == true)
            {
                if(trim(document.customerForm['customer.shippingLocations['+i+'].address1'].value).length == 0)
                {
                    var pa=document.getElementById("errors");
                    pa.innerHTML = 'Address 1 cannot be blank if a Shipping Address is selected as Default Shipping Address';
                    document.customerForm['customer.shippingLocations['+i+'].address1'].focus();
                    return;
                }
                if( document.customerForm['customer.shippingLocations['+i+'].defaultAddress'].checked == true
                && document.customerForm['customer.shippingLocations['+i+'].remove'].checked == true )
                {

                     var pa1=document.getElementById("errors");
                     pa1.innerHTML = '<br>'+'Both  Remove and DefaultShippingAddress should not be selected ';
                     return;
                }

            }
            i++;
        }

        var found = 0;
        for ( var i = 0; i < billingLocationsSize ; i++ )
        {
            if( document.customerForm['customer.billingLocations['+i+'].defaultAddress'].checked == true )
              { found++;}
        }
        if ( found > 1)
        {
             var pa=document.getElementById("errors");
             pa.innerHTML = '<br>'+'Select only one default billing Address';
             return;
        }

        found = 0;
        for ( var i = 0; i < a ; i++ )
        {
            if( document.customerForm['customer.shippingLocations['+i+'].defaultAddress'].checked == true )
              { found++;}
        }
        if ( found > 1)
        {
             var pa=document.getElementById("errors");
             pa.innerHTML = '<br>'+'Select only one default shipping Address';
             return;
        }

         document.customerForm['customer.contactPersonObject.phoneNumber'].disabled == false;
         document.customerForm['customer.contactPersonObject.cellNumber'].disabled == false;
         document.customerForm['customer.contactPersonObject.faxNumber'].disabled == false;
         document.customerForm['customer.contactPersonObject.email'].disabled == false;

        if( document.customerForm['customer.customerNumber'].disabled==true )
        {
            document.customerForm['customer.customerNumber'].disabled=false;
        }

        theForm.action.value = "SaveCustomer";
        theForm.submit();
    }

    function addNewItems(addElement)
    {
        if(addElement == 'Region')
        {
            var pa=document.getElementById("enterRegion");
            if(document.customerForm['customer.region'].value == -1)
            {
                pa.innerHTML = "<font class='NArialL' ><font color='darkblue'>Add new region</font></font>";
                document.customerForm['customer.newRegion'].style.visibility="visible";
                document.customerForm['customer.newRegion'].focus();
            }
            else
            {
                pa.innerHTML = "";
                document.customerForm['customer.newRegion'].style.visibility="hidden";
            }

            if(compareRegion() == false) return;
        }
        else if(addElement == 'RepOffice')
        {
            var pa=document.getElementById("enterRepOffice");
            if(document.customerForm['customer.repOffice'].value == -1)
            {
                pa.innerHTML = "<font class='NArialL' ><font color='darkblue'>Add new rep office</font></font>";
                document.customerForm['customer.newRepOffice'].style.visibility="visible";
                document.customerForm['customer.newRepOffice'].focus();
            }
            else
            {
                pa.innerHTML = "";
                document.customerForm['customer.newRepOffice'].style.visibility="hidden";
            }

            if(compareRepOffice() == false) return;
        }
        else if(addElement == 'SalesPerson')
        {
            var pa=document.getElementById("enterSalesPerson");
            if(document.customerForm['customer.salesPerson'].value == -1)
            {
                pa.innerHTML = "<font class='NArialL' ><font color='darkblue'>Add new sales person</font></font>";
                document.customerForm['customer.newSalesPerson'].style.visibility="visible";
                document.customerForm['customer.newSalesPerson'].focus();
            }
            else
            {
                pa.innerHTML = "";
                document.customerForm['customer.newSalesPerson'].style.visibility="hidden";
            }
            if(compareSalesPerson() == false) return;
        }
        else if(addElement == 'SalesRep')
        {
            var pa=document.getElementById("enterSalesRep");
            if(document.customerForm['customer.salesRep'].value == -1)
            {
                pa.innerHTML = "<font class='NArialL' ><font color='darkblue'>Add new sales rep</font></font>";
                document.customerForm['customer.newSalesRep'].style.visibility="visible";
                document.customerForm['customer.newSalesRep'].focus();
            }
            else
            {
                pa.innerHTML = "";
                document.customerForm['customer.newSalesRep'].style.visibility="hidden";
            }

            if(compareSalesRep() == false) return;
        }
    }

    function openEndUser()
    {
        var endUserId = document.customerForm['customer.endUserName'].value;

        var customerId = document.customerForm['customer.customerId'].value;
        if(endUserId != "")
        {
            if( endUserId == -1)
            {
                newWindow = window.open ('<%=chipTracContext%>/endUser.do?action=CreateEndUser&customerId='+customerId,'enduseroptionsPopupOpen','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=800,height=700,resizable=yes');
                if(!newWindow.opener) {newWindow.opener = window}
                newWindow.focus();
            }
            else
            {
                newWindow = window.open ('<%=chipTracContext%>/endUser.do?action=EditEndUser&endUserId='+endUserId,'enduseroptionsPopupOpen','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=800,height=700,resizable=yes');
                if(!newWindow.opener) {newWindow.opener = window}
                newWindow.focus();
            }
        }
    }

    function selectCustomerSalesPersonRelation()
    {
        var customerId = document.customerForm['customer.customerId'].value ;
        var customerName = document.customerForm['customer.customerName'].value;
        var LeftPos=(screen.width)?(screen.width-500)/2:100;
        var TopPos=(screen.height)?(screen.height-450)/2:100;
        newWindow = window.open ('<%=chipTracContext%>/customerSalesPersonRelationship.do?action=searchSalesPersons&customerId='+customerId+'&customerName='+customerName,'customerSalespersons','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=540,height=500,resizable=yes,Left= '+LeftPos+',top='+TopPos);
        if(!newWindow.opener) {newWindow.opener = window}
        newWindow.focus();
    }

    function addOptionToSelect(aName, aValue)
    {
        var salesPersonObj = document.customerForm['customer.salesPerson'];
        var alreadyExistFlag = false;
        if( typeof salesPersonObj != 'undefined' )
        {
            for( var i=0 ; i < salesPersonObj.options.length ; i++ )
            {
                if( aValue ==  salesPersonObj.options[i].value)
                {
                    alreadyExistFlag = true;
                    break;
                }
            }
        }
        if( alreadyExistFlag == false )
        {
            addOption(salesPersonObj, aName + "", aValue, salesPersonObj.options.length);
            for( var i=0 ; i < salesPersonObj.options.length ; i++ )
            {
                if(salesPersonObj.options[i].value == document.customerForm.salesPersonName.value)
                {
                    salesPersonObj.options[i].selected = true;
                }
            }

        }
    }

    function addOption(aSelect, aName, aValue, anIndex)
    {
       var aOption = new Option(aName, aValue)
       aSelect.options[anIndex] = aOption;
    }

    function deleteAllOptions()
    {

        var salesPersonObj = document.customerForm['customer.salesPerson'];
        var optionValue1 = document.customerForm['customer.salesPerson'].value;

        if( typeof salesPersonObj !='undefined' )
        {
            for( var j = salesPersonObj.options.length ; j >= 0 ; j-- )
            {
                 salesPersonObj.options[j] = null;
            }
        }
    }

    function loadRegion()
    {
         for( ff = 0; ff < salesPersons.length; ff++ )
         {
            if( document.customerForm['customer.salesPerson'].value == salesPersons[ff] )
            {
                 document.customerForm['customer.region'].value = regionNames[ff];
                 break;
            }
            else
            {
                 document.customerForm['customer.region'].value = '';
            }
         }

    }
    function assignShippingInstructions(elementName)
    {
        var shippingInstructions = document.getElementById("shippingInstructions");
        if ( elementName.value == "-1" )
        {
            shippingInstructions.innerHTML = "<bean:message key="label.sales.shippingInstructions" />"
            document.customerForm['customer.shippingInstructions'].value = "";
            document.customerForm['customer.shippingInstructions'].readOnly = true;
        }
        else if ( elementName.value == "-2")
        {
            shippingInstructions.innerHTML = "New <bean:message key="label.sales.shippingInstructions" />"
            document.customerForm['customer.shippingInstructions'].value = "";
            document.customerForm['customer.shippingInstructions'].readOnly = false;
            document.customerForm['customer.shippingInstructions'].focus();
        }
        else if ( Number( elementName.value ) > 0 )
        {

            document.customerForm.action.value = "loadShippingInstructions";
            if( document.customerForm['customer.customerNumber'].disabled==true )
            {
                document.customerForm['customer.customerNumber'].disabled=false;
            }
            document.customerForm.submit();
        }
    }

    function refresh()
    {
        if( document.customerForm['customer.customerNumber'].disabled==true )
        {
            document.customerForm['customer.customerNumber'].disabled=false;
        }
        document.customerForm.submit();
    }
    function showHideIsDefaultConsignment()
    {
        var form = document.customerForm;
        var pa=document.getElementById("errors");
        pa.innerHTML = "";
        var isConsigneeCtrl = form['customer.isConsignee'];
        var isTrackInventoryCtrl = form['customer.isTrackInventory'];
        var isDefaultConsignmentCtrl = form['customer.isDefaultConsignment'];
        var isDefaultConsignmentSpan = document.getElementById( "isDefaultConsignmentSpan")
        if ( isConsigneeCtrl.checked )
        {
            var isDistributorCtrl = form['customer.isDistributor'];
            if ( isDistributorCtrl.checked )
            {
                isConsigneeCtrl.checked = false;
                pa.innerHTML = "<li>Customer cannot be both Distributer and a Consignee, Please uncheck Is Distributer check box"
                return;
            }
            isTrackInventoryCtrl.value = "true";
            isDefaultConsignmentSpan.style.display = "block";
        }
        else
        {
            isDefaultConsignmentCtrl.checked = false;
            isDefaultConsignmentSpan.style.display = "none";
        }
    }
    function showHideDistributerOptions()
    {
        var form = document.customerForm;
        var pa=document.getElementById("errors");
        pa.innerHTML = "";
        var isDistributorCtrl = form['customer.isDistributor'];
        var isTrackInventoryCtrl = form['customer.isTrackInventory'];
        var revenueTypeCtrl = form['customer.revenueType'];
        var distributorOptionsSpan = document.getElementById( "distributorOptionsSpan")
        if ( isDistributorCtrl.checked )
        {
            var isConsigneeCtrl = form['customer.isConsignee'];
            if ( isConsigneeCtrl.checked )
            {
                isDistributorCtrl.checked = false;
                pa.innerHTML = "<li>Customer cannot be both Distributer and a Consignee, Please uncheck Is Consignee check box"
                return;
            }
            distributorOptionsSpan.style.display = "block";
        }
        else
        {
            isTrackInventoryCtrl.value = "true";
            distributorOptionsSpan.style.display = "none";
        }
    }

    function AddShippingTerms ()
	{
		var shippinglabel = document.getElementById("newShippingTerms");

		if(document.customerForm['customer.shippingTerms'].value == -2 )
		{
			document.customerForm['customer.newShippingTerms'].style.visibility = "visible";
			document.customerForm['customer.newShippingTerms'].value = '';
			shippinglabel.innerHTML = "New Pay Terms : ";
		}
		else
		{
			 document.customerForm['customer.newShippingTerms'].style.visibility = "hidden";
			 shippinglabel.innerHTML = "";
		}
	}
    function deleteAllListOptions( listCtrl )
    {
        if( typeof listCtrl !='undefined' )
        {
            for( var j = listCtrl.options.length ; j >= 0 ; j-- )
            {
                 listCtrl.options[j] = null;
            }
        }
    }
    function addOptionToList(listCtrl, aName, aValue)
    {
       addOption(listCtrl, aName, aValue, listCtrl.options.length)
    }

</SCRIPT>
</HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload="load();">
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
    <TR>
        <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
            <!-- Side Navigation start -->
            <%@ include file="/jsp/sales/sales_menu.jsp" %>
            <!-- end of the side navigations -->
        </td>
        <td bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></td>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">
            <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
            <BR>
            <html:form name="customerForm" method="post" action="/customers.do"  type="com.scalar.chiptrack.sales.forms.CustomerForm" onsubmit = "document.customerForm['customer.customerNumber'].disabled=false">
            <nested:nest property="customer">
			<center><span class="NArialW">Customer Profile</span></center>
			<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
			<nested:hidden property="customerId" />
			<table border="0" width="90%" align=right>
				<% if ( !user1.isActionAllowed ( Functionality.CUSTOMER_DETAILS,User.USER_ACTION_MODIFY ) ) { %>
				<tr>
					<td colspan=5 align='left'>
						<font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b> </font> </font>
					</td>
				</tr> 
				<% } %>
				<tr><td colspan='5'><chiptrack:errors styleClass="NArialL" /></td></tr>
				<tr><td colspan='5' align="left" class='NArialL'><FONT id="errors" styleClass="NArialL" color='FF0000'></FONT></TD></TR>
				<tr>
					<td width="20%"><font class="NArialL" >Customer Type:<font color=red>*</font><font color=red></font></font></td>
					<td colspan="4">
						<logic:iterate id="customerTypes" name="customerTypesCollection">
						<font class="NArialL">
						<nested:multibox property="selectedCustomerTypes" styleClass="txfiled">
							<bean:write name="customerTypes" property="value" />
						</nested:multibox>
						<bean:write name="customerTypes" property="label" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						</font>
						</logic:iterate>
					</td>
				</tr>
				<tr><td colspan='5' align="left" class='NArialL'>&nbsp;</TD></TR>
                <tr>
					<td width="20%"><font class="NArialL" >Customer Name:<font color=red>*</font></font></td>
					<td width="20%">
						<font class="NArialL" >
						<nested:text property="customerName" styleClass="txfield" maxlength="50"/>
                        <nested:hidden property="customRequirements" value="false"/>
                        <nested:hidden property="ecnChangeNotification" value="false" />
                        <nested:hidden property="printName"/>
                        <nested:hidden property="supplierNumber"/>
                        <nested:hidden property="contractNumber"/>
                        <nested:hidden property="specificationNumber"/>
                        </font>
                    </td>
					<td width="8%">&nbsp;</td>
					<td width="24%" nowrap><font class="NArialL" >Customer Number:<font color=red>*</font></font></td>
					<td width="25%"><font class="NArialL">
					<%
						Customer tempCustomer = ( ( CustomerForm )session.getAttribute( "customerForm" ) ).getCustomer();
						if( tempCustomer.getCustomerId() < 0 )
						{
					%>
                        <nested:text property="customerNumber" size="20" styleClass="txfield" maxlength="20"/>
                    <%  } else { %>
                        <nested:text property="customerNumber" size="20" styleClass="txfield" maxlength="20" disabled="true"/>
                    <%  } %>
                    </td>
				</tr>
				<tr><td colspan='5' align="left" class='NArialL'>&nbsp;</TD></TR>
                <tr>
					<td width="24%" class="NArialL">Is Sample Customer:</td>
					<td width="25%" class="NArialL"><nested:checkbox property="isSample" onclick="showHideDistributerOptions()" styleClass="txfield"/></td>
					<td width="8%">&nbsp;</td>
					<td width="20%" class='NArialL'>&nbsp;</td>
					<td width="20%">&nbsp;</td>
				</tr>
                <tr>
					<td width="24%" class="NArialL">Is Distributer:</td>
					<td width="25%" class="NArialL"><nested:checkbox property="isDistributor" onclick="showHideDistributerOptions()" styleClass="txfield"/></td>
					<td width="8%">&nbsp;</td>
					<td width="20%" class='NArialL'>Is Consignee:</td>
					<td width="20%"><nested:checkbox property="isConsignee" onclick="showHideIsDefaultConsignment()" styleClass="txfield"/></td>
				</tr>
				<tr>
					<td width="49%" colspan="2">
						<span id="distributorOptionsSpan" style="display:none">
						<table>
							<tr>
								<td class="NArialL">Track Inventory:</td>
								<td>
									<nested:select property="isTrackInventory" styleClass="txfield">
										<html:option value="true">Yes</html:option>
										<html:option value="false">No</html:option>
									</nested:select>
								</td>
							</tr>
							<tr>
								<td class="NArialL">Consider Revenue As:</td>
								<td>
									<%
										String revenueTypeRevenue = Constants.REVENUE_TYPE_REVENUE + "";
										String revenueTypeDefferedRevenue = Constants.REVENUE_TYPE_DEFFERED_REVENUE + "";
									%>
									<nested:select property="revenueType" styleClass="txfield">
										<html:option value="<%=revenueTypeRevenue%>">Revenue</html:option>
										<html:option value="<%=revenueTypeDefferedRevenue%>">Deffered Revenue</html:option>
									</nested:select>
								</td>
							</tr>
						</table>
						</span>
					</td>
					<td width="8%">&nbsp;</td>
					<td width="40%" colspan="2" class='NArialL'><span id="isDefaultConsignmentSpan" style="display:none"><nested:checkbox property="isDefaultConsignment" styleClass="txfield"/>&nbsp;Is Default for All Sales Orders</span></td>
				</tr>
				<tr>
					<td width="24%"><font class="NArialL" >Phone No:</font></td>
					<td width="25%"><font class="NArialL" ><nested:text property="billingAddress.phoneNumber" size="20" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/></font></td>
					<td width="8%">&nbsp;</td>
					<td width="20%"><font class="NArialL" >Fax No:</font></td>
					<td width="20%"><nested:text property="billingAddress.faxNumber" size="20" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/></td>
				</tr>
				<tr>
					<td width="20%"><font class="NArialL" >Email:</font></td>
					<td width="32%"><nested:text property="billingAddress.email" size="20" styleClass="txfield" maxlength="50"  /></td>
					<td width="8%">&nbsp;</td>
					<td width="20%"></td>
					<td width="20%"></td>
				</tr>
				<tr>
					<td width="20%"><font class="NArialL" >Contact Person:</font></td>
					<td width="20%">
						<nested:select property="contactPerson" styleClass="txfield" onchange="javascript:selectContactPerson('CustomerContactPerson',0);">
							<option value =""/>
							<option value="-1" >--Edit Contact Person--</option>
							<option value=""/>
							<html:options name="customerContactPersonsList"/>
						</nested:select>
					</td>
					<td width="8%">&nbsp;</td>
					<td width="20%"><font class="NArialL" >Phone No:</font></td>
					<td width="32%"><font class="NArialL" ><nested:text property="contactPersonObject.phoneNumber" size="20" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/></font></td>
				</tr>
				<tr>
					<td width="20%"><font class="NArialL" >Cell No:</font></td>
					<td width="20%"><nested:text property="contactPersonObject.cellNumber" size="20" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/></td>
					<td width="8%"></td>
					<td width="20%"><font class="NArialL" >Fax No:</font></td>
					<td width="32%"><nested:text property="contactPersonObject.faxNumber" size="20" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/></td>
				</tr>
				<tr>
					<td width="20%"><font class="NArialL" >Email:</font></td>
					<td width="20%"><nested:text property="contactPersonObject.email" size="20" styleClass="txfield" maxlength="50" /></td>
					<td width="8%">&nbsp;</td>
				</tr>
				<tr>
					<td width="20%"><font class="NArialL" ><bean:message key="label.sales.salesOrder.ShippingMethod" />:</font></td>
					<td width="20%">
						<select name="customer.shippingMethod1" class="txfield" onchange="javascript:addShippingMethod(this);">
							<option value="-1" >----- Select -----</option>
							<option value="" ></option>
							<%
							java.util.ArrayList shippingMethods1 = null;
							shippingMethods1 = (java.util.ArrayList)request.getAttribute("shippingMethods");
							org.apache.struts.util.LabelValueBean shippingMethod1;
							String selectedMethod1 = (String)request.getAttribute("Method1");
							String selectedAccount1 = (String)request.getAttribute("Account1");

							String shipAccount = request.getParameter("shipAccount1");

							for( int aa=0; aa < shippingMethods1.size(); aa++)
							{
								shippingMethod1 = (org.apache.struts.util.LabelValueBean)(shippingMethods1.get(aa));
								String label1 = shippingMethod1.getLabel();
								String value1 = shippingMethod1.getValue();

								if( selectedMethod1 != null)
								{
									if(selectedMethod1.trim().equalsIgnoreCase(label1.trim()))
									{
							%>
										<option value="<%=selectedMethod1%>" selected><%=selectedMethod1%></option>
							<%		} else { %>
										<option value="<%=label1%>" ><%=label1%></option>
							<%		
									} 
								}
								else
								{
							%>
										<option value="<%=label1%>" ><%=label1%></option>
							<%
								}
							}
							%>
							<nested:greaterThan value="0" property="customerId">
								<option value="-2" >----- Edit -----</option>
							</nested:greaterThan>
							<nested:lessEqual value="0" property="customerId">
								<option value="-2" >Add <bean:message key="label.sales.salesOrder.NewShippingMethod"/> </option>
							</nested:lessEqual>
						</select>
					</td>
						<nested:hidden property="shippingAccount1" />
					<td width="8%">&nbsp;</td>
					<td width="20%" class="NArialL">Delivery Terms:</td>
					<td width="32%">
						<nested:select property="deliveryTermsId" styleClass="txfield">
							<html:option value="0">----- select ----- </html:option>
							<html:options collection="deliveryTerms" property="value" labelProperty="label"/> 
						</nested:select>
					</td>
				</tr>
				<tr>
					<td width="20%"><font class="NArialL" id="newShippingMethod1"><bean:message key="label.sales.salesOrder.NewShippingMethod"/>:</font></td>
					<td width="20%"><nested:text property="newShippingMethod1" size="20" styleClass="txfield" maxlength="50" /></td>
					<td width="8%">&nbsp;</td>
					<td width="20%"><font class="NArialL" id="newShippingAccount1"><bean:message key="label.sales.salesOrder.NewShippingAccount"/>:</font></td>
					<td width="32%"><nested:text property="newShippingAccount1" size="20" styleClass="txfield" maxlength="50" /></td>
				</tr>
				<tr>
					<td width="20%" ><font class="NArialL" >Region:</font></td>
					<td width="20%" >
						<nested:select property="region" styleClass="txfield" onchange="javascript:getNewElements('Region');">
							<option value =""/>
							<option value="-1" >--Edit Region--</option>
							<option value =""/>
							<html:options name="regions"/>
						</nested:select>
					</td>
					<td width="8%"></td>
					<td width="20%" ><font class="NArialL" >Regional Rep:</font></td>
					<td width="32%" >
						<nested:select property="repOffice" styleClass="txfield" onchange="javascript:getNewElements('Rep Office');">
							 <option value =""/>
							 <option value="-1" >--Edit Regional Rep--</option>
							 <option value =""/>
							 <html:options name="repOffices" />
						</nested:select>
					</td>
				</tr>
				<tr>
					<td width="20%" ><span id="enterRegion"></span></td>
					<td width="20%" ><nested:text property="newRegion" styleClass="txfield" maxlength="50" onkeyup="javascript:compareRegion()" /></td>
					<td width="8%"></td>
					<td width="20%" ><span id="enterRepOffice"></span></td>
                    <td width="32%" ><nested:text property="newRepOffice" styleClass="txfield" maxlength="50" onkeyup="javascript:compareRepOffice()"/></td>
				</tr>
				<tr>
					<td width="20%" ><font class="NArialL" >Sales Person:</font></td>
					<td width="20%" >
						<nested:select property="salesPerson" styleClass="txfield" onchange="javascript:loadRegion();">
							<option value="" >----select----</option>
							<html:options collection="salesPersonsList" property="value" labelProperty="label"/>
						</nested:select>
						<input type="hidden" name="salesPersonName" value="<%=tempCustomer.getSalesPerson()%>"/>
					</td>
					<td width="8%"></td>
					<td width="20%"><font class="NArialL">JIT Window: </font></td>
					<td width="20%"><nested:text property="jitWindow" styleClass="valuetxfield" maxlength="4"  /></td>
				</tr>
				<tr>
					<td width="20%" colspan="3"><font class="NArialL">Please <a styleClass="leftsection" href="javascript:selectCustomerSalesPersonRelation()" onmouseover="window.status='Click to select Customer/Sales Person Relationship';return true" onmouseout="window.status='';return true">
					Click here</a>&nbsp;to Add Customer/Sales Person Relationships
					</font></td>
					<td width="8%">&nbsp;</td>
					<td width="20%">&nbsp;</td>
				</tr>
				<tr>
					<td width="20%"><span id="enterSalesPerson"></span></td>
					<td width="20%"><nested:text property="newSalesPerson" styleClass="txfield" maxlength="50" onkeyup="javaScript:compareSalesPerson()" /></td>
					<td width="8%">&nbsp;</td>
					<td width="20%">&nbsp;</td>
					<td width="20%">&nbsp;</td>
				</tr>
				<tr>
					<td width="20%" ><font class="NArialL" ><bean:message key="label.sales.salesRep.Name"/> :</font></td>
					<td width="20%" >
					<nested:select property="salesRep" styleClass="txfield" onchange="javascript:getNewElements('Sales Rep');">
						<option value =""/>
						<option value="-1" >--Edit <bean:message key="label.sales.salesRep.Name"/>--</option>
						<option value =""/>
						<html:options name="salesRepList" />
					</nested:select>
				</td>
				<%
				String editValue =(String)session.getAttribute("showCustomer");
				if( ( "FALSE".equals( editValue ) ) == true ) 
				{
				%>
				<td width="8%">&nbsp;</td>
				<td colspan="2">
					<font class="NArialL">
						Please &nbsp;&nbsp;
						<a styleClass="leftsection" href="javascript:selectPartNumbers()" onmouseover="window.status='Click to select Customer Partnumber';return true" onmouseout="window.status='';return true">
					    click here
						</a>
						&nbsp;&nbsp;to create <bean:message key="label.sales.customerPartNumberLinkMessage" />
					</font>
				</td>
				<%}%>
			</tr>
			<tr>
				<td width="20%"><span id="enterSalesRep"></span></td>
				<td width="20%">
					<nested:text property="newSalesRep" styleClass="txfield" maxlength="50" onkeyup="javaScript:compareSalesRep()" />
				</td>
				<td width="8%">&nbsp;</td>
				<td width="20%" class="NArialL">&nbsp;</td>
				<td width="20%">&nbsp;</td>
			</tr>
			<tr>
				<td width="13%"><font class="NArialL">Pay Terms :</font></td>
				<td width="18%">
					<nested:select  property="shippingTerms" styleClass="txfield" onchange="javascript:AddShippingTerms()">
						<option value="" >----- Select -----</option>
						<html:options name="allShippingTerms" />
						<html:option value="-2" >-- Add New Pay Terms --</html:option>
					</nested:select>
				</td>
			</tr>
			<tr>
				<td width="13%"><font class="NArialL" id="newShippingTerms">New Pay Terms:</font></td>
				<td width="18%"><nested:text  property="newShippingTerms" size="23" maxlength="50" styleClass="txfield" /></td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >All Shipping Instructions :</font></td>
				<td colspan="2" width="55%">
					<nested:select property="shippingInstructionsId" styleClass="txfield" onchange="javascript:assignShippingInstructions(this);">
						<html:options collection="shippingInstructions" property="value" labelProperty="label"/>
					</nested:select>
				</td>
				<td width="5%" class="NArialL">Holds</td>
				<td width="20%">
					<table border="0" cellSpacing="2" cellPadding="0">
						<tr>
							<td class="NArialL" bgcolor="#DEE1E2">Mktg</td>
							<td class="NArialL" bgcolor="#DEE1E2">Fin</td>
							<td class="NArialL" bgcolor="#DEE1E2">Ops</td>
							<td class="NArialL" bgcolor="#DEE1E2">Sales</td>
						</tr>
						<tr>
							<td>
								<nested:select property="marketingHold" styleClass="txfield">
									<html:option value=""></html:option>
									<html:option value="0">X</html:option>
									<html:options collection="marketingReasonCodes" property="value" labelProperty="label"/>
								</nested:select>
							</td>
							<td>
								<nested:select property="financeHold" styleClass="txfield">
									<html:option value=""></html:option>
									<html:option value="0">X</html:option>
									<html:options collection="financeReasonCodes" property="value" labelProperty="label"/>
								</nested:select>
							</td>
							<td>
								<nested:select property="operationsHold" styleClass="txfield">
									<html:option value=""></html:option>
									<html:option value="0">X</html:option>
									<html:options collection="opsReasonCodes" property="value" labelProperty="label"/>
								</nested:select>
							</td>
							<td>
								<nested:select property="salesHold" styleClass="txfield">
									<html:option value=""></html:option>
									<html:option value="0">X</html:option>
									<html:options collection="salesReasonCodes" property="value" labelProperty="label"/>
								</nested:select>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td width="20%">&nbsp;</td>
				<td colspan="2" width="55%">&nbsp;</td>
				<td width="5%" class="NArialL">Sample Holds</td>
				<td width="20%">
					<table border="0" cellSpacing="2" cellPadding="0">
						<tr>
							<td>
								<nested:select property="sampleMarketingHold" styleClass="txfield">
									<html:option value=""></html:option>
									<html:option value="0">X</html:option>
									<html:options collection="marketingReasonCodes" property="value" labelProperty="label"/>
								</nested:select>
							</td>
							<td>
								<nested:select property="sampleFinanceHold" styleClass="txfield">
									<html:option value=""></html:option>
									<html:option value="0">X</html:option>
									<html:options collection="financeReasonCodes" property="value" labelProperty="label"/>
								</nested:select>
							</td>
							<td>
								<nested:select property="sampleOperationsHold" styleClass="txfield">
									<html:option value=""></html:option>
									<html:option value="0">X</html:option>
									<html:options collection="opsReasonCodes" property="value" labelProperty="label"/>
								</nested:select>
							</td>
							<td>
								<nested:select property="sampleSalesHold" styleClass="txfield">
									<html:option value=""></html:option>
									<html:option value="0">X</html:option>
									<html:options collection="salesReasonCodes" property="value" labelProperty="label"/>
								</nested:select>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
			<tr>
				<td colspan=5 class="NArialL" >
					<font class="NArialL" id="shippingInstructions">
					<bean:message key="label.sales.shippingInstructions" />
					</font>
					<br>
					<nested:textarea property="shippingInstructions" rows="4" cols="60" styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(document.customerForm['customer.shippingInstructions'],300)" onkeyup="javascript:setTextAreaMaxLength(document.customerForm['customer.shippingInstructions'],300)"/>
				</td>
			</tr>
			<tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
			<tr>
				<td width="20%" bgcolor="#DEE1E2" colspan=5><font class="NArialL" >Default Billing Address:</font></td>
			</tr>
			<nested:hidden property="defaultBillingAddressId" />
			<nested:hidden property="billAddressId" />
			<tr>
				<td width="20%"><font class="NArialL" >Address 1:</font></td>
				<td width="20%">
					<nested:text property="billingAddress.address1" size="23" styleClass="txfield" maxlength="50"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Address 2:</font></td>
				<td width="32%">
					<nested:text property="billingAddress.address2" size="23" styleClass="txfield" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Address 3:</font></td>
				<td width="20%">
					<nested:text property="billingAddress.address3" size="23" styleClass="txfield" maxlength="50"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Address 4:</font></td>
				<td width="32%">
					<nested:text property="billingAddress.address4" size="23" styleClass="txfield" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >City:</font></td>
				<td width="20%">
					<nested:text property="billingAddress.city" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_CITY_MAX_LENGTH)%>"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >State:</font></td>
				<td width="32%">
					<nested:text property="billingAddress.state" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_STATE_MAX_LENGTH)%>" />
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Zip:</font></td>
				<td width="20%">
					<nested:text property="billingAddress.zipCode" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_ZIP_MAX_LENGTH)%>"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Country:</font></td>
				<td width="32%">
					<nested:text property="billingAddress.country" size="23" styleClass="txfield" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Contact Person:</font></td>
				<td width="20%">
					<nested:select property="billingAddress.contactPerson" styleClass="txfield" onchange="javascript:selectContactPerson('BillingContactPerson',0,0);">
						<option value =""/>
						<option value="-1" >--Edit Contact Person--</option>
						<option value =""/>
						<html:options name="billingContactPersonsList"/>
					</nested:select>
				</td>
				<td width="8%">&nbsp;</td>
				<td width="20%"><font class="NArialL" >Phone No:</font></td>
				<td width="32%"><font class="NArialL" ><nested:text property="billingContactPersonObject.phoneNumber" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_PHONE_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/></font></td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Cell No:</font></td>
				<td width="20%"><nested:text property="billingContactPersonObject.cellNumber" size="23" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/></td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Fax No:</font></td>
				<td width="32%"><nested:text property="billingContactPersonObject.faxNumber" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_FAX_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/></td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Email:</font></td>
				<td width="20%"><nested:text property="billingContactPersonObject.email" size="23" styleClass="txfield" maxlength="50" /></td>
				<td width="8%">&nbsp;</td>
                <td width="20%"><font class="NArialL" ><bean:message key="label.address.tagName"/>:</font></td>
				<td width="32%"><nested:text property="billingAddress.tagName" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_TAGNAME_MAX_LENGTH)%>"/></td>
            </tr>
            <% int k=0; %>
			<nested:iterate property="billingLocations">
			<tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
			<tr>
				<td colspan=5 bgcolor="#DEE1E2"><font class="NArialL" >Billing Address - <%=++k%>:</font>
					<nested:hidden property="locAddressId" />
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<nested:checkbox property="remove" value="true" /> <FONT class='NArialL'>Remove </FONT>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<font class="Arial Narrow" size="-1">
					<nested:checkbox property="defaultAddress" value="true"/> Default Billing Address
					</font>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Address 1:</font></td>
				<td width="20%">
					<nested:text property="address1" styleClass="txfield" size="23" maxlength="50"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Address 2:</font></td>
				<td width="32%">
					<nested:text property="address2" styleClass="txfield" size="23" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Address 3:</font></td>
				<td width="20%">
					<nested:text property="address3" size="23" styleClass="txfield" maxlength="50"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Address 4:</font></td>
				<td width="32%">
					<nested:text property="address4" size="23" styleClass="txfield" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >City:</font></td>
				<td width="20%">
					<nested:text property="city" styleClass="txfield" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_CITY_MAX_LENGTH)%>"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >State:</font></td>
				<td width="32%">
					<nested:text property="state" styleClass="txfield" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_STATE_MAX_LENGTH)%>" />
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Zip:</font></td>
				<td width="20%">
					<nested:text property="zipCode" styleClass="txfield" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_ZIP_MAX_LENGTH)%>"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Country:</font></td>
				<td width="32%">
					<nested:text property="country" styleClass="txfield" size="23" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Contact Person:</font></td>
				<td width="20%">
					<%
					String test = "javascript:selectContactPerson('BillingLocationContactPerson', document.customerForm['customer.billingLocations["+ (k-1) + "].addressId'].value, "+(k-1)+")";
					%>
					<nested:select property="contactPerson" styleClass="txfield" onchange="<%=test%>" >
						<option value =""/>
						<option value="-1" >--Edit Contact Person--</option>
						<option value =""/>
						<nested:options property="contactPersons"/>
					</nested:select>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Phone No:</font></td>
				<td width="32%">
					<nested:text property="contactPersonObject.phoneNumber" styleClass="txfield" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_PHONE_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Cell No:</font></td>
				<td width="20%">
					<nested:text property="contactPersonObject.cellNumber" styleClass="txfield" size="23" maxlength="50" onkeypress='validatePhoneNumber(this)'/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Fax No:</font></td>
				<td width="32%">
					<nested:text property="contactPersonObject.faxNumber" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_FAX_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Email:</font></td>
				<td width="20%">
					<nested:text property="contactPersonObject.email" size="23" styleClass="txfield" maxlength="50" />
				</td>
                <td width="8%"></td>
                <td width="20%"><font class="NArialL" ><bean:message key="label.address.tagName"/>:</font></td>
				<td width="32%"><nested:text property="tagName" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_TAGNAME_MAX_LENGTH)%>"/></td>
            </tr>
			<nested:hidden property="addressId" />
			</nested:iterate>
			<input type="hidden" name="billingLocationsSize" id="billingLocationsSize" value="<%=k%>" >
            <% if(ConfigManager.isMultipleBillingAddressesAllowed()) { %>
                <tr>
                    <td colspan=5><nested:submit property="addBillingLocation">Add Billing Address</nested:submit></td>
                </tr>
            <% } %>
            <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
			<tr>
				<td width="20%" bgcolor="#DEE1E2" colspan=5>
					<font class="NArialL" >Default Shipping Address:</font>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<font class="Arial Narrow" size="-1">
						<input type="checkbox" name="sameas" value="yes" onclick="javascript:applyBillingAddress();">
						(Same as billing address) 
					</font>
				</td>
			</tr>
			<nested:hidden property="defaultShippingAddressId" />
			<nested:hidden property="shipAddressId" />
			<nested:hidden property = "shippingAddress.epicoreShipCode"/>
			<tr>
				<td width="20%"><font class="NArialL" >Address 1:</font></td>
				<td width="20%">
					<nested:text property="shippingAddress.address1" size="23" styleClass="txfield" maxlength="50"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Address 2:</font></td>
				<td width="32%">
					<nested:text property="shippingAddress.address2" size="23" styleClass="txfield" maxlength="50"/>
				</td>
			</tr>
			<tr>
			<td width="20%"><font class="NArialL" >Address 3:</font></td>
				<td width="20%">
					<nested:text property="shippingAddress.address3" size="23" styleClass="txfield" maxlength="50"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Address 4:</font></td>
				<td width="32%">
					<nested:text property="shippingAddress.address4" size="23" styleClass="txfield" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >City:</font></td>
				<td width="20%">
					<nested:text property="shippingAddress.city" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_CITY_MAX_LENGTH)%>"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >State:</font></td>
				<td width="32%">
					<nested:text property="shippingAddress.state" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_STATE_MAX_LENGTH)%>" />
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Zip:</font></td>
				<td width="20%">
					<nested:text property="shippingAddress.zipCode" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_ZIP_MAX_LENGTH)%>"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Country:</font></td>
				<td width="32%">
					<nested:text property="shippingAddress.country" size="23" styleClass="txfield" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Contact Person:</font></td>
				<td width="20%">
					<nested:select property="shippingAddress.contactPerson" styleClass="txfield" onchange="javascript:selectContactPerson('ShippingContactPerson',document.customerForm['customer.defaultShippingAddressId'].value,0);">
						<option value =""/>
						<option value="-1" >--Edit Contact Person--</option>
						<option value =""/>
						<html:options name="shippingContactPersonsList"/>
					</nested:select>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Phone No:</font></td>
				<td width="32%">
					<nested:text property="shippingContactPersonObject.phoneNumber" styleClass="txfield" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_PHONE_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/>
				</td>
			<tr>
				<td width="20%"><font class="NArialL" >Cell No:</font></td>
				<td width="20%">
					<nested:text property="shippingContactPersonObject.cellNumber" styleClass="txfield" size="23" maxlength="50" onkeypress='validatePhoneNumber(this)'/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Fax No:</font></td>
				<td width="32%">
					<nested:text property="shippingContactPersonObject.faxNumber" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_FAX_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Email:</font></td>
				<td width="20%">
					<nested:text property="shippingContactPersonObject.email" size="23" styleClass="txfield" maxlength="50" />
				</td>
                <td width="8%"></td>
                <td width="20%"><font class="NArialL" ><bean:message key="label.address.tagName"/>:</font></td>
				<td width="32%"><nested:text property="shippingAddress.tagName" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_TAGNAME_MAX_LENGTH)%>"/></td>
            </tr>
			<% int i=0; %>
			<nested:iterate property="shippingLocations">
			<tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
			<input type="hidden" name="count" value='<%=i%>' />
			<tr>
				<td colspan=5 bgcolor="#DEE1E2"><font class="NArialL" >Shipping Address - <%=++i%>:</font>
					<nested:hidden property="locAddressId" />
					<nested:hidden property="epicoreShipCode"/>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<nested:checkbox property="remove" value="true" /> <FONT class='NArialL'>Remove </FONT>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<font class="Arial Narrow" size="-1">
					<nested:checkbox property="defaultAddress" value="true"/> Default Shipping Address 
					</font>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Address 1:</font></td>
				<td width="20%">
					<nested:text property="address1" styleClass="txfield" size="23" maxlength="50"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Address 2:</font></td>
				<td width="32%">
					<nested:text property="address2" styleClass="txfield" size="23" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Address 3:</font></td>
				<td width="20%">
					<nested:text property="address3" size="23" styleClass="txfield" maxlength="50"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Address 4:</font></td>
				<td width="32%">
					<nested:text property="address4" size="23" styleClass="txfield" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >City:</font></td>
				<td width="20%">
					<nested:text property="city" styleClass="txfield" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_CITY_MAX_LENGTH)%>"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >State:</font></td>
				<td width="32%">
					<nested:text property="state" styleClass="txfield" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_STATE_MAX_LENGTH)%>" />
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Zip:</font></td>
				<td width="20%">
					<nested:text property="zipCode" styleClass="txfield" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_ZIP_MAX_LENGTH)%>"/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Country:</font></td>
				<td width="32%">
					<nested:text property="country" styleClass="txfield" size="23" maxlength="50"/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Contact Person:</font></td>
				<td width="20%">
					<%
					String test = "javascript:selectContactPerson('ShippingLocationContactPerson', document.customerForm['customer.shippingLocations["+ (i-1) + "].addressId'].value, "+(i-1)+")";
					%>
					<nested:select property="contactPerson" styleClass="txfield" onchange="<%=test%>" >
						<option value =""/>
						<option value="-1" >--Edit Contact Person--</option>
						<option value =""/>
						<nested:options property="contactPersons"/>
					</nested:select>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Phone No:</font></td>
				<td width="32%">
					<nested:text property="contactPersonObject.phoneNumber" styleClass="txfield" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_PHONE_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Cell No:</font></td>
				<td width="20%">
					<nested:text property="contactPersonObject.cellNumber" styleClass="txfield" size="23" maxlength="50" onkeypress='validatePhoneNumber(this)'/>
				</td>
				<td width="8%"></td>
				<td width="20%"><font class="NArialL" >Fax No:</font></td>
				<td width="32%">
					<nested:text property="contactPersonObject.faxNumber" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_FAX_MAX_LENGTH)%>" onkeypress='validatePhoneNumber(this)'/>
				</td>
			</tr>
			<tr>
				<td width="20%"><font class="NArialL" >Email:</font></td>
				<td width="20%">
					<nested:text property="contactPersonObject.email" size="23" styleClass="txfield" maxlength="50" />
				</td>
                <td width="8%"></td>
                <td width="20%"><font class="NArialL" ><bean:message key="label.address.tagName"/>:</font></td>
				<td width="32%"><nested:text property="tagName" size="23" styleClass="txfield" maxlength="<%=ConfigManager.getProperty(ConfigManager.ADDRESS_TAGNAME_MAX_LENGTH)%>"/></td>
            </tr>
			<nested:hidden property="addressId" />
			</nested:iterate>
			<input type="hidden" id="locSize" name="locSize" value="<%=i%>" >
			<tr> 
				<td colspan=5><nested:submit property="addShippingLocation">Add Location</nested:submit></td>
			</tr>
			<tr>
				<td colspan=5><font id=font1>&nbsp;&nbsp;</font></td>
			</tr>
			<tr><td colspan=5>&nbsp;&nbsp;</td></tr>
			<!-- Adding the next page from here -->
			<tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
			<tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=30></td></tr>
			<tr>
                <td colspan=5 align=center>
					<chiptrack:restrictedLink functionality='<%=Functionality.CUSTOMER_DETAILS%>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href="javascript:submitpage(document.customerForm);" onmouseover="window.status='Click to save Customer';return true" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" title="Click here to Save Customer"/></chiptrack:restrictedLink>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="javascript:document.customerForm.reset();" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" title="Click here to Reset"></a>
				</td>
			</tr>
			<!-- The next page will end here -->
		</table>
		<input type="hidden" name="counter"   value="2">
		<input type="hidden" name="action" value="" />
		</nested:nest>
		<input type="hidden" name="shipMethod1" value=""/>
		<input type="hidden" name="shipAccount1" value="<%=request.getAttribute("Method1")%>"/>
		</html:form>
		<!-- till here -->
		<BR><BR><BR></TD>
		<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
	</TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
<script language="javascript">

function compareRegion()
{
    var pa = document.getElementById("errors");
    pa.innerHTML = "";

    var count = document.customerForm['customer.region'].length;
    var new_region = document.customerForm['customer.newRegion'].value ;

    if( document.customerForm['customer.region'].value == "-1" && new_region.trim() != "")
    {
        for(i=0;i<count;i++)
        {
            var existing_region = document.customerForm['customer.region'].options[i].value;
            existing_region = existing_region.trim();

            if(new_region.toLowerCase() == existing_region.toLowerCase())
            {
                    pa.innerHTML = "* "+ new_region +" region already available in Region list.";
                    document.customerForm['customer.newRegion'].focus;
                    return false;
            }
        }
    }
    else
    {
        document.customerForm['customer.newRegion'].value = "";
    }
}

function compareRepOffice()
{
    var pa = document.getElementById("errors");
    pa.innerHTML = "";

    var count = document.customerForm['customer.repOffice'].length;
    var new_rep_office = document.customerForm['customer.newRepOffice'].value ;

    if( document.customerForm['customer.repOffice'].value == "-1" && new_rep_office.trim() != "" )
    {
        for(i=0;i<count;i++)
        {
            var existing_rep_office = document.customerForm['customer.repOffice'].options[i].value;
            existing_rep_office = existing_rep_office.trim();

                if(new_rep_office.toLowerCase() == existing_rep_office.toLowerCase())
                {
                    pa.innerHTML = "* "+ new_rep_office +" Rep Office already available in Rep Office list.";
                    document.customerForm['customer.newRepOffice'].focus;
                    return false;
                }
        }
    }
    else
    {
        document.customerForm['customer.newRepOffice'].value = "";
    }
}

function compareSalesPerson()
{
    var pa = document.getElementById("errors");
    pa.innerHTML = "";

    var count = document.customerForm['customer.salesPerson'].length;
    var new_sales_person = document.customerForm['customer.newSalesPerson'].value ;

    if( document.customerForm['customer.salesPerson'].value == "-1" && new_sales_person.trim() != "" )
    {
        for(i=0;i<count;i++)
        {
            var existing_sales_person = document.customerForm['customer.salesPerson'].options[i].value;
            existing_sales_person = existing_sales_person.trim();

                if(new_sales_person.toLowerCase() == existing_sales_person.toLowerCase())
                {
                    pa.innerHTML = "* "+ new_sales_person +" Sales Person already available in Sales Person list.";
                    document.customerForm['customer.newSalesPerson'].focus;
                    return false;
                }
        }
    }
    else
    {
        document.customerForm['customer.newSalesPerson'].value = "";
    }
}

function compareSalesRep()
{
    var pa = document.getElementById("errors");
    pa.innerHTML = "";

    var count = document.customerForm['customer.salesRep'].length;
    var new_sales_rep = document.customerForm['customer.newSalesRep'].value ;

    if( document.customerForm['customer.salesRep'].value == "-1" && new_sales_rep.trim() != "" )
    {
        for(i=0;i<count;i++)
        {
            var existing_sales_rep = document.customerForm['customer.salesRep'].options[i].value;
            existing_sales_rep = existing_sales_rep.trim();

                if(new_sales_rep.toLowerCase() == existing_sales_rep.toLowerCase())
                {
                    pa.innerHTML = "* "+ new_sales_rep +" Sales Rep already available in Sales Rep list.";
                    document.customerForm['customer.newSalesRep'].focus;
                    return false;
                }
        }
    }
    else
    {
        document.customerForm['customer.newSalesRep'].value = "";
    }
}

</script>
<script language="javascript">
function shipping_method_exists()
{
    var method1     = document.customerForm['customer.shippingMethod1'].value;
    var pa=document.getElementById("errors");
    pa.innerHTML = '';

   if( method1 == -2)
   {
        var newmethod1  = document.customerForm['customer.newShippingMethod1'].value;
        var tempShippingMethod =  newmethod1.trim();

        for(var i = 0; i < shppingLables.length - 1; i++)
        {
           if(  shppingLables[i].substring( 0, shppingLables[i].indexOf("#") ).toUpperCase().trim() == tempShippingMethod.toUpperCase() )
           {
                pa.innerHTML = newmethod1 + ' <bean:message key="label.sales.salesOrder.ShippingMethod" /> already Exists, Please enter another <bean:message key="label.sales.salesOrder.ShippingMethod" />';
           }
       }
   }
   if( pa.innerHTML == '' )
   {
        submitpage(document.customerForm);
   }
   else
   {
     document.customerForm['customer.newShippingMethod1'].focus();
     document.customerForm['customer.newShippingMethod1'].select();
   }
}
</script>
</BODY>
</HTML>
